package com.tnovoselec.android.feed.handler.resultholders;

import java.util.ArrayList;
import java.util.List;

import com.tnovoselec.android.favorites.entity.MeteoFavoritesDto;

public class WeatherResultHolder {

    private static List<MeteoFavoritesDto> RESULT = new ArrayList<MeteoFavoritesDto>();

    private WeatherResultHolder() {
	super();
    }

    public static void init(List<MeteoFavoritesDto> items) {
	WeatherResultHolder.RESULT.clear();
	if (items != null) {
	    WeatherResultHolder.RESULT.addAll(items);
	}
    }

    public static void clear() {
	WeatherResultHolder.RESULT.clear();
    }

    public static MeteoFavoritesDto get(int index) {
	return WeatherResultHolder.RESULT.get(index);
    }

    public static List<MeteoFavoritesDto> getAll() {
	// TODO vratiti novu referencu?
	return RESULT;
	// return new ArrayList<MeteoFavoritesDto>(WeatherResultHolder.RESULT);
    }

    public static int size() {
	return WeatherResultHolder.RESULT.size();
    }

    public static int getVisibleItemsCount() {
	int count = 0;
	for (MeteoFavoritesDto mdf : RESULT) {
	    if (mdf.isVisible()) {
		count++;
	    }
	}
	return count;
    }

    public static MeteoFavoritesDto getItemByPosition(int position) {
	for (MeteoFavoritesDto item : RESULT) {
	    if (item.getPosition() == position) {
		return item;
	    }
	}
	return null;
    }

    public static List<MeteoFavoritesDto> getAllVisible() {
	List<MeteoFavoritesDto> visibleItems = new ArrayList<MeteoFavoritesDto>();
	for (MeteoFavoritesDto m : RESULT) {
	    if (m.isVisible()) {
		visibleItems.add(m);
	    }
	}
	return visibleItems;
    }

    public static MeteoFavoritesDto get(String cityId) {
	for (MeteoFavoritesDto meteo : RESULT) {
	    if (meteo.getCityId().equals(cityId)) {
		return meteo;
	    }
	}
	return null;
    }

}
